﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;

using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using System.Collections.Generic;
using HZ.DrugTrade.BLLFactory;
using HZ.DrugTrade.IBLL;
using HZ.DrugTrade.Model;
using HZ.DrugTrade.Model.Enum;

namespace HZ.DrugTrade.Web.Admin.BidProdManage
{
    public partial class BidProductAddList : BasePage
    {
        public BidProductAddList()
        {
            this.ModuleNo = Module.采购产品管理.ToString();
        }

        IBLL_Goods ig = Factory.BLL_Goods();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                SetBind();
            }
        }

        protected void btnQuery_Click(object sender, EventArgs e)
        {
            AspNetPager1.CurrentPageIndex = 1;
            StoreQueryCondition();
            SetBind();
        }

        private void SetBind()
        {
            HZ.DrugTrade.Model.Query.Goods goods = GetQueryCondition();
            if (goods == null)
            {
                StoreQueryCondition();
                goods = GetQueryCondition();
            }

            //AspNetPager1.PageSize = Constants.GRIDVIEW_PAGE_SIZE;
            gvwBidDrug.PageSize = AspNetPager1.PageSize;
            int totalCount = 0;
            IList<HZ.DrugTrade.Model.View.Goods> goodsList = ig.GetGoodsByWhere(goods, AspNetPager1.CurrentPageIndex, AspNetPager1.PageSize, out totalCount);
            AspNetPager1.RecordCount = totalCount;
            gvwBidDrug.DataSource = goodsList;
            gvwBidDrug.DataBind();
        }

        /// <summary>
        /// 将查询条件存储到viewstate中
        /// </summary>
        private void StoreQueryCondition()
        {
            HZ.DrugTrade.Model.Query.Goods where = new HZ.DrugTrade.Model.Query.Goods();
            where.CompanyName_SC = txtProduceCompany_SC.Text.Trim();
            where.CompanyName_TB = txtCompany_TB.Text.Trim();
            where.Material = txtMaterial.Text.Trim();
            where.GoodsName = txtGoodsName.Text.Trim();
            where.Outlookc = txtOutLook.Text.Trim();
            where.Unit = txtUnit.Text.Trim();
            where.SortFields = " GoodsName asc";

            ViewState["v_goods"] = where;
        }

        /// <summary>
        /// 讲查询条件从viewstate中取出
        /// </summary>
        private HZ.DrugTrade.Model.Query.Goods GetQueryCondition()
        {
            HZ.DrugTrade.Model.Query.Goods goods = (HZ.DrugTrade.Model.Query.Goods)ViewState["v_goods"];
            return goods;
        }

        protected void AspNetPager1_OnPageChanged(object sender, EventArgs e)
        {
            SetBind();
        }

    }
}
